package hojadetrabajo4;

public class doublyLinkedNode <E>
{
    protected E data;
    protected doublyLinkedNode<E> nextElement;
    protected doublyLinkedNode<E> previousElement;

    public doublyLinkedNode(E v,
                            doublyLinkedNode<E> next,
                            doublyLinkedNode<E> previous)
    {
        data = v;
        nextElement = next;
        if (nextElement != null)
            nextElement.previousElement = this;
        previousElement = previous;
        if (previousElement != null)
            previousElement.nextElement = this;
    }

    public doublyLinkedNode(E v)
    // post: constructs a single element
    {
        this(v,null,null);
    }
    
    public void setNext(doublyLinkedNode<E> next)
       // post: sets reference to new next value
       {
          nextElement = next;
       }
    
    public doublyLinkedNode<E> getNext()
       // post: sets reference to new next value
       {
          return nextElement;
       }
    
    public E value()
       // post: returns value associated with this element
       {
          return data;
       }
    
    public doublyLinkedNode<E> getPrevious ()
       // post: returns value associated with this element
       {
          return previousElement;
       }

}